package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.BasePageList;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.assemble.BusinessAssembler;
import com.tarena.lbs.basic.web.service.BusinessService;
import com.tarena.lbs.pojo.basic.bo.BusinessBO;
import com.tarena.lbs.pojo.basic.param.BusinessParam;
import com.tarena.lbs.pojo.basic.query.BusinessQuery;
import com.tarena.lbs.pojo.basic.vo.BusiStoreVO;
import com.tarena.lbs.pojo.basic.vo.BusinessVO;
import com.tarena.lbs.pojo.basic.vo.DictItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class BusinessController {
    @Autowired
    private BusinessService businessService;
    @Autowired
    private BusinessAssembler businessAssembler;

    @GetMapping("/admin/basic/business/info/list")
    public Result<PageResult<BusinessVO>> pageList(BusinessQuery businessQuery){
        //业务层给我返回一个可以封装pageResult属性的对象 pageNo pageSize total objects
        //业务返回的数据 total objects
        BasePageList<BusinessBO> boList = businessService.pageList(businessQuery);
        PageResult<BusinessVO> pageVOS = businessAssembler.assemblePageResultVO(boList,businessQuery);
        return new Result<>(pageVOS);
    }

    @GetMapping("/admin/basic/dictItem/info/getlistAll/{dictId}")
    public Result<List<DictItemVO>> getlistAll(){
        List<DictItemVO> dictItemVOS = businessAssembler.assembleStaticBusinessTypes();
        return new Result<>(dictItemVOS);
    }

    //新增商家
    @PostMapping("/admin/basic/business/info/save")
    public Result<Void> businessSave(@RequestBody BusinessParam businessParam)throws BusinessException{
        businessService.businessSave(businessParam);
        return Result.success();
    }

    //随着互动 查询商家 以及商家下的店铺列表
    @GetMapping("/basic/business/info/detail/{id}")
    public Result<BusiStoreVO> businessStores(@PathVariable Integer id)
            throws BusinessException{
        BusiStoreVO vo=businessService.businessStore(id);
        return new Result<>(vo);
    }
}
